package refactortips.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;

public abstract class AbstractRefactorTipsEditorHandler extends AbstractHandler {

	/**
	 * the command has been executed, so extract extract the needed information
	 * from the application context.
	 */
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		try {
			IWorkbenchPage activePage = window.getActivePage();
			activePage.openEditor(new GeneralEditorInput(getEditorName(), "Refactor Tips"), getEditorName());
			
			//IViewPart viewPart = activePage.showView(getViewName());
			//PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			//		.getActivePage().activate(viewPart);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
		// IWorkbenchPage page = window.getActivePage();
		// View view = (View) page.finfindView(View.TOP);
		// MessageDialog.openInformation(
		// window.getShell(),
		// "MenuPlug",
		// "Hello, Eclipse world");
		return null;
	}

	public abstract String getEditorName();
}
